﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace General.Core.Data
{
    /// <summary>
    /// 
    /// </summary>
    /// <typeparam name="TEntity"></typeparam>
    public interface IRepository<TEntity> where TEntity : class
    {
        DbContext DbContext { get; }
        DbSet<TEntity> Entities { get; }

        IQueryable<TEntity> Table { get; }

        /// <summary>
        /// 通过主键id获取数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        TEntity getById(object id);
        ValueTask<TEntity> getByIdAsync(object id);
        int insert(TEntity entity, bool IsCommit = true);
        int delete(TEntity entity, bool IsCommit = true);
        Task<TEntity> GetAsync(Expression<Func<TEntity, bool>> query = null, bool ignoreQueryFilters = false);
        Task<int> CountAsync(Expression<Func<TEntity, bool>> query = null, bool ignoreQueryFilters = false);
        Task<bool> IsExistAsync(Expression<Func<TEntity, bool>> query = null, bool ignoreQueryFilters = false);
        IQueryable<TEntity> GetAllAsync(Expression<Func<TEntity, bool>> query = null, bool ignoreQueryFilters = false);
        Task<int> insertAsync(TEntity entity);
        Task<int> AddListAsync(List<TEntity> lists);
        int update(TEntity entity);
        Task<int> UpdateAsync(TEntity entity);
        Task<int> UpdateListAsync(List<TEntity> lists);
        Task<int> DeleteAsync(TEntity entity);
        Task<int> DeleteListAsync(List<TEntity> lists);
        /// <summary>
        /// 执行sql命令
        /// </summary>
        /// <returns></returns>
        Task<int> ExecuteSqlAsync(string sql);
    }
}
